<?php
namespace app\beautiful\helper\payment;
use app\common\helper\payment\PaymentBaseHelper;
use app\beautiful\model\order\StoreOrderModel;
use app\beautiful\logic\LogsLogic;
use app\beautiful\model\member\MemberCouponModel;
use app\beautiful\logic\MemberWalletLogic;
use app\common\model\ShopGmvLogsModel;
use app\beautiful\logic\PartnerLogic;
//每个子类只需要专注于自己的 respond 逻辑
class PaymentStoreOrderHelper extends PaymentBaseHelper{
    protected  $moudel = 'beautiful';
    protected  $orderKey = 'ms'; //给一个KEY增大吞吐量
    protected  $respondAction = 'storeMallRespond';
    
    public function respondCallback($orderId,$payInfo,$fail){
         $order = StoreOrderModel::find($orderId);
        if(null === $order) return;      
        if($order->is_paid == 0){
            $order->is_paid  = 1;
            $order->pay_info = $payInfo;
            $order->pay_type = 'weixin';
            $order->status =  4; //订单的状态值
            $order->pay_time = time();
            $order->save();           
            $MemberWalletLogic = new MemberWalletLogic($order->shop_id, $order->member_id);
            $needPay = $order->need_pay;
            $MemberWalletLogic->addIntegralByPayment($needPay); //更新支付返的积分
            //分销记录
            /*$PartnerLogic = new PartnerLogic($order->shop_id);
            $PartnerLogic->commission($order->member_id,$needPay);*/

            //分红
            $PartnerLogic = new PartnerLogic($order->shop_id);
            $PartnerLogic->commissionNew($order->member_id,$needPay,'storeOrder',$orderId);


            //插入日志
            $shop_gmv_logs = new ShopGmvLogsModel();
            $shop_gmv_logs->shop_id=$order->shop_id;
            $shop_gmv_logs->balance=$needPay;
            $shop_gmv_logs->save();
        }
    }
}